﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using YasharEl.Infrastructure.OrgUnit.EntityModel;

namespace YasharEl.Infrastructure.OrgUnit.PersistanceModel.NHibernate.Mappings
{
    public class OrganizationalUnitEntityMap : ClassMap<OrganizationalUnitEntity>
    {
        public OrganizationalUnitEntityMap()
        {
            ReadOnly();
            Cache.ReadOnly();
            Table("RKV_MIS_ICHIDOT_IRGONIOT");
            Id(e => e.Id)
                .Column("KOD_ICHIDA_IRGONIT")
                .GeneratedBy.Assigned();
            Map(e => e.Description)
                .Column("TOR_ICHIDA_IRGONIT")
                .Not.Nullable();
            References(e => e.ParentUnit)
                .Column("KPOF_LICHIDA_ARGONIT")
                .LazyLoad()
                .Class<OrganizationalUnitEntity>()
                .Fetch.Select();
            HasMany<OrganizationalUnitEntity>(e => e.DirectChilds)
                .Inverse()
                .LazyLoad()
                .Cascade.All()
                .KeyColumn("KPOF_LICHIDA_ARGONIT");
            HasMany<EmployeeEntity>(e => e.DirectMembers)
                .Inverse()
                .LazyLoad()
                .Cascade.All()
                .KeyColumn("UNITCODE");
        }
    }
}
